<?php
/**
 * Created by PhpStorm.
 * User: 郑好
 * Date: 2019/6/28
 * Time: 下午2:18
 */

namespace app\common\validate;

use app\common\InstanceTrait;
use think\Validate;

class AdminOpLogValidate
{
    use InstanceTrait;

    public function checkPager($data)
    {
        foreach ($data as $key=>$value) {
            if (!is_array($value)) {
                $data[$key] = htmlentities($value);
            }
        }

        $rule = [
            "page_no" => "number|gt:0",
            "page_count" => "number|between:10,50",
        ];
        $msg  =   [
            "page_no.number"   => "页码必须是数字",
            "page_no.gt"  => "页码必须大于0",
            "page_count.number"  => "每页数量必须是数字",
            "page_count.between"  => "每页数量必须在10-50之间",
        ];

        $validate = Validate::make($rule, $msg);
        $result = $validate->check($data);

        if (!$result) {
            return ["code" =>_MSG_INVALID_CLIENT_PARAM, "msg" => $validate->getError()];
        }
        return ["code" =>_MSG_SYSTEM_SUCCESS, "msg" => "校验成功", "data" => $data];
    }
}
